using System; 
using System.IO;
using Doc.Xroad.Eu;
using Doc.Xroad.Eu.Headers;
using Doc.Xroad.Eu.Messages;
using Xtee.Core.Adapter.Service;
using Xtee.Core.Envelope;
using Xtee.Core.Envelope.Header;
using Xtee.XteeAdapter.Doc; 
 
namespace DocumentServingApplication.Services
{
    public class GetDocumentService : GetDocumentServiceHandler
    {
        public GetDocumentResponse ProcessRequest(GetDocumentRequest input, GetDocumentInputHeader header)
        {
            if (string.IsNullOrEmpty(input.Id))
                throw new ApplicationException("Document friendly name is required");

            string file = Configurator.GetConfig().Storage.TempRoot + "\\" + input.Id;

            if (!File.Exists(file))
                throw new ApplicationException("Document with name : " + input.Id + " Does not exists!");

            return new GetDocumentResponse(new Document(input.Id, new FileInfo(file))); ;
        }
    }

}
